package com.leha.utils;

/**
 * Created by xiabin on 2017/11/7.
 */
public class LocationPoint {
    private Double lat;
    private Double lng;
    private static final double EARTH_RADIUS = 6378137;

    private static double rad(double d){
        return d * Math.PI / 180.0;
    }

    public Double getLat() {
        return lat;
    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    public Double getLng() {
        return lng;
    }

    public void setLng(Double lng) {
        this.lng = lng;
    }

    public LocationPoint(Double _lat, Double _lng) {
        this.lat = _lat;
        this.lng = _lng;
    }

    double Distance(LocationPoint pb) {
        double radLat1 = rad(this.lat);
        double radLat2 = rad(pb.lat);
        double a = radLat1 - radLat2;
        double b = rad(this.lng) - rad(pb.lng);
        double s = 2 * Math.asin(
                Math.sqrt(
                        Math.pow(Math.sin(a/2),2)
                                + Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)
                )
        );
        s = s * EARTH_RADIUS;
        s = Math.round(s * 10000) / 10000;
        return s;
    }
}
